﻿#include "modelinfodlg.h"
#include "ui_modelinfodlg.h"
#include <QMessageBox>
#include <QRegExpValidator>

ModelInfoDlg::ModelInfoDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ModelInfoDlg)
{
    ui->setupUi(this);
    this->setWindowTitle(QStringLiteral("模型信息"));
    QRegExp exp("^[^?v*|""<>:/]{1,256}$"); // fixme 无法包括\\，不得不单独处理
    QValidator *validator = new QRegExpValidator(exp, this);
    ui->editName->setValidator( validator );
}

ModelInfoDlg::~ModelInfoDlg()
{
    delete ui;
}

void ModelInfoDlg::on_btnOK_clicked()
{
    m_modelName = ui->editName->text().trimmed();
    m_labelList = ui->plainTextEdit->toPlainText().trimmed();
    if(m_modelName.isEmpty()){
        QMessageBox::information(NULL,QStringLiteral("保存"),QStringLiteral("模型名称不能为空"));
        return;
    }
    if(m_labelList.isEmpty()||!m_labelList.contains("\n")){
        QMessageBox::information(NULL,QStringLiteral("保存"),QStringLiteral("请检查模型标签是否正确"));
        return;
    }
    done(Accepted);
}

void ModelInfoDlg::on_btnCancel_clicked()
{
    done(Rejected);
}
